#include "mapObject.h"

mapObject::mapObject(): parentMap( NULL ),
                        type( MOB_UNKNOWN )
{
        coordinates.X_coord = 0;
        coordinates.Y_coord = 0;
}
mapObject::mapObject(mapObject* mo):    parentMap( mo->getParentMap() ),
                                        type( mo->getType() ),
                                        coordinates( mo->getCoord() )
{}
mapObject::~mapObject(){}

void mapObject::setParentMap(mapCtr* mp){
    parentMap = mp;
}
mapCtr* mapObject::getParentMap(){ return parentMap; }

void mapObject::setType(unsigned char tp){
    type = tp;
}
unsigned char mapObject::getType(){
    return type;
}

void mapObject::setCoord(unsigned int x, unsigned int y){
    coordinates.X_coord = x;
    coordinates.Y_coord = y;
}
void mapObject::setCoord(coord_t cd){
    coordinates = cd;
}
unsigned int mapObject::getX(){ return coordinates.X_coord; }
unsigned int mapObject::getY(){ return coordinates.Y_coord; }
coord_t mapObject::getCoord(){ return coordinates; }
f_coord_t mapObject::getFCoord(){
    f_coord_t coord;
    coord.X_coord = coordinates.X_coord;
    coord.Y_coord = getGridY(coordinates.Y_coord,coordinates.X_coord);
    return coord;
}

bool mapObject::move(direc_t direction,unsigned int distance){

    int xoff = 0;
    int yoff = 0;

    if( direction == DIR_UP ){
        yoff = distance;
    }else if( direction == DIR_DOWN ){
        yoff = -distance;
    }else if( direction == DIR_U_LEFT ){
        xoff = -distance;
        if( coordinates.X_coord % 2 ){
            yoff = distance / 2;
        }else{
            if( distance % 2 ){
                yoff = distance / 2 + 1;
            }else{
                yoff = distance / 2;
            }
        }
    }else if( direction == DIR_D_LEFT ){
        xoff = -distance;
        if( coordinates.X_coord % 2 ){
            if( distance % 2 ){
                yoff = -(distance / 2 + 1);
            }else{
                yoff = -(distance / 2);
            }
        }else{
            yoff = -(distance/2);
        }
    }else if( direction == DIR_U_RIGHT ){
        xoff = distance;
        if( coordinates.X_coord % 2 ){
            yoff = distance / 2;
        }else{
            if( distance % 2 ){
                yoff = distance / 2 + 1;
            }else{
                yoff = distance / 2;
            }
        }
    }else if( direction == DIR_D_RIGHT ){
        xoff = distance;
        if( coordinates.X_coord % 2 ){
            if( distance % 2 ){
                yoff = -(distance / 2 + 1);
            }else{
                yoff = -(distance / 2);
            }
        }else{
            yoff = -(distance/2);
        }
    }

    coordinates.X_coord += xoff;
    coordinates.Y_coord += yoff;

    return true;
}
